home *** CD-ROM | disk | FTP | other *** search
/ OpenGL Superbible (2nd Edition) / OpenGL SuperBible e2.iso / tools / FLTK-1.0.6 / src / gl_draw.cxx < prev    next >
Encoding:
C/C++ Source or Header  |  1999-01-07  |  4.0 KB  |  147 lines

  1. //
  2. // "$Id: gl_draw.cxx,v 1.7 1999/01/07 19:17:46 mike Exp $"
  3. //
  4. // OpenGL drawing support routines for the Fast Light Tool Kit (FLTK).
  5. //
  6. // Copyright 1998-1999 by Bill Spitzak and others.
  7. //
  8. // This library is free software; you can redistribute it and/or
  9. // modify it under the terms of the GNU Library General Public
  10. // License as published by the Free Software Foundation; either
  11. // version 2 of the License, or (at your option) any later version.
  12. //
  13. // This library is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16. // Library General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Library General Public
  19. // License along with this library; if not, write to the Free Software
  20. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  21. // USA.
  22. //
  23. // Please report all bugs and problems to "fltk-bugs@easysw.com".
  24. //
  25.  
  26. // Functions from <FL/gl.h>
  27. // See also Fl_Gl_Window and gl_start.C
  28.  
  29. #include <config.h>
  30. #if HAVE_GL
  31.  
  32. #include <FL/Fl.H>
  33. #include <FL/gl.h>
  34. #include <FL/x.H>
  35. #include <FL/fl_draw.H>
  36. #include "Fl_Gl_Choice.H"
  37. #include "Fl_Font.H"
  38. #include <string.h>
  39.  
  40. void  gl_font(int fontid, int size) {fl_font(fontid, size);}
  41. int   gl_height() {return fl_height();}
  42. int   gl_descent() {return fl_descent();}
  43. double gl_width(const char* s) {return fl_width(s);}
  44. double gl_width(const char* s, int n) {return fl_width(s,n);}
  45. double gl_width(uchar c) {return fl_width(c);}
  46.  
  47. void gl_draw(const char* str, int n) {
  48.   if (!fl_fontsize->listbase) {
  49. #ifdef WIN32
  50.     int base = fl_fontsize->metr.tmFirstChar;
  51.     int size = fl_fontsize->metr.tmLastChar-base+1;
  52.     HFONT oldFid = (HFONT)SelectObject(fl_gc, fl_fontsize->fid);
  53.     fl_fontsize->listbase = glGenLists(256);
  54.     wglUseFontBitmaps(fl_gc, base, size, fl_fontsize->listbase+base); 
  55.     SelectObject(fl_gc, oldFid);
  56. #else
  57.     int base = fl_xfont->min_char_or_byte2;
  58.     int size = fl_xfont->max_char_or_byte2-base+1;
  59.     fl_fontsize->listbase = glGenLists(256);
  60.     glXUseXFont(fl_xfont->fid, base, size, fl_fontsize->listbase+base);
  61. #endif
  62.   }
  63.  
  64.   glPushAttrib(GL_LIST_BIT);
  65.     glListBase(fl_fontsize->listbase);
  66.     glCallLists(n, GL_UNSIGNED_BYTE, str);
  67.   glPopAttrib();
  68. }
  69.  
  70. void gl_draw(const char* str, int n, int x, int y) {
  71.   glRasterPos2i(x, y);
  72.   gl_draw(str, n);
  73. }
  74.  
  75. void gl_draw(const char* str, int n, float x, float y) {
  76.   glRasterPos2f(x, y);
  77.   gl_draw(str, n);
  78. }
  79.  
  80. void gl_draw(const char* str) {
  81.   gl_draw(str, strlen(str));
  82. }
  83.  
  84. void gl_draw(const char* str, int x, int y) {
  85.   gl_draw(str, strlen(str), x, y);
  86. }
  87.  
  88. void gl_draw(const char* str, float x, float y) {
  89.   gl_draw(str, strlen(str), x, y);
  90. }
  91.  
  92. static void gl_draw_invert(const char* str, int n, int x, int y) {
  93.   glRasterPos2i(x, -y);
  94.   gl_draw(str, n);
  95. }
  96.  
  97. void gl_draw(
  98.   const char* str,     // the (multi-line) string
  99.   int x, int y, int w, int h,     // bounding box
  100.   Fl_Align align) {
  101.   fl_draw(str, x, -y-h, w, h, align, gl_draw_invert);
  102. }
  103.  
  104. void gl_measure(const char* str, int& x, int& y) {fl_measure(str,x,y);}
  105.  
  106. void gl_rect(int x, int y, int w, int h) {
  107.   if (w < 0) {w = -w; x = x-w;}
  108.   if (h < 0) {h = -h; y = y-h;}
  109.   glBegin(GL_LINE_STRIP);
  110.   glVertex2i(x+w-1, y+h-1);
  111.   glVertex2i(x+w-1, y);
  112.   glVertex2i(x, y);
  113.   glVertex2i(x, y+h-1);
  114.   glVertex2i(x+w, y+h-1);
  115.   glEnd();
  116. }
  117.  
  118. #if HAVE_GL_OVERLAY
  119. extern uchar fl_overlay;
  120. #endif
  121.  
  122. void gl_color(Fl_Color i) {
  123. #if HAVE_GL_OVERLAY
  124. #ifdef WIN32
  125.   if (fl_overlay) {glIndexi(i ? i : FL_GRAY_RAMP); return;}
  126. #else
  127.   if (fl_overlay) {glIndexi(int(fl_xpixel(i))); return;}
  128. #endif
  129. #endif
  130.   uchar red, green, blue;
  131.   Fl::get_color(i, red, green, blue);
  132.   glColor3ub(red, green, blue);
  133. }
  134.   
  135. void gl_draw_image(const uchar* b, int x, int y, int w, int h, int d, int ld) {
  136.   if (!ld) ld = w*d;
  137.   glPixelStorei(GL_UNPACK_ROW_LENGTH, ld/d);
  138.   glRasterPos2i(x,y);
  139.   glDrawPixels(w,h,d<4?GL_RGB:GL_RGBA,GL_UNSIGNED_BYTE,(const ulong*)b);
  140. }
  141.  
  142. #endif
  143.  
  144. //
  145. // End of "$Id: gl_draw.cxx,v 1.7 1999/01/07 19:17:46 mike Exp $".
  146. //
  147.